from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import status
from rest_framework import viewsets, mixins
from rest_framework.response import Response
from core.tools.throttles import TransferRateThrottle
from .models import Province, City, District, BankCode
from .serializers import ProvinceSerializer, CitySerializer, DistrictSerializer, ShortMsgSerializer, BankCodeSerializer


class ProvinceViewSet(viewsets.GenericViewSet, mixins.ListModelMixin):
    serializer_class = ProvinceSerializer
    queryset = Province.objects.all()


class CityViewSet(viewsets.GenericViewSet, mixins.ListModelMixin):
    serializer_class = CitySerializer
    # filter_backends = (DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter)
    filter_backends = (DjangoFilterBackend,)
    filter_fields = ("province",)
    queryset = City.objects.all()


class CountyViewSet(viewsets.GenericViewSet, mixins.ListModelMixin):
    serializer_class = DistrictSerializer
    filter_backends = (DjangoFilterBackend,)
    filter_fields = ("city",)
    queryset = District.objects.all()


class ShortMsgViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):
    serializer_class = ShortMsgSerializer
    throttle_classes = (TransferRateThrottle,)

class BankCodeViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
    queryset = BankCode.objects.all()
    serializer_class = BankCodeSerializer
